function abort(){
    param($msg)
    Write-Output "Error: $msg ... aborting"
    exit 1
}
$configDir="$env:USERPROFILE\.vlassist"
$configFile="${configDir}\config.json"
$applications="$PSScriptRoot\applications.ahk"

if (!(test-path $configFile))
{
    New-Item -Path "$env:USERPROFILE" -Name ".vlassist" -ItemType "directory"
    Copy-Item "${PSScriptRoot}\config.json.template" "${configFile}" -Force
}

$collections = (get-content ${configFile} | convertfrom-json).Collections

set-content $applications ";Do not modify this config file which is auto generatued by assist config.json"
add-content $applications ""
add-content $applications ""


foreach($item in $collections)
{
    if($item.Key){
        $name = $item.Name
        $key = $item.Key
        $type = $item.Type
        $action =  $key.replace("``","````")
        add-content $applications "; $name"
        add-content $applications "$key::"
        add-content $applications "HotKey(`"${action}`")"
        add-content $applications "return"
        add-content $applications ""
        Write-Output "genearte ${name} to ${applications}"
    }
}

Write-Output "Generate task has been done!"